package model

import (
	"time"
)

const (
	GROUP_USER_ROLE_IS_OWNER  byte = 1
	GROUP_USER_ROLE_IS_ADMIN  byte = 2
	GROUP_USER_ROLE_IS_MEMBER byte = 3
)

const (
	PostsNotifyOn  = 1
	PostsNotifyOff = 2
)

type GroupsUsers struct {
	GroupsUsersModifiable `xorm:"extends"`
	AppsId                uint  `json:"apps_id" xorm:"apps_id not null unique(apps_groupid_user_id) comment('app id') INT"`
	GroupId               int64 `json:"group_id" xorm:"group_id BIGINT notnull unique(apps_groupid_user_id) comment('群组id')"`
	UserId                int64 `json:"user_id" xorm:"user_id BIGINT notnull unique(apps_groupid_user_id) comment('用户id')"`
	// 角色 1:拥有者 2:管理员 3:成员
	Role                  byte  `json:"role" xorm:"role TINYINT notnull default 2 comment('角色 1:拥有者 2:管理员 3:成员')"`
	Status                int8  `json:"status" xorm:"status TINYINT notnull default 1 comment('状态 -1:软删 0:待审核 1:正常')"`

	Joined  time.Time `json:"joined" xorm:"joined TIMESTAMP"`
	Created time.Time `json:"created" xorm:"'created' created TIMESTAMP"`
}

type GroupsUsersModifiable struct {
	// 新帖子时通知,1为开启, 2为关闭, 默认为1
	PostsNotify int `json:"posts_notify" xorm:"posts_notify int default 1"`
	// 群昵称
	Nickname string `json:"nickname" xorm:"not null comment('昵称') VARCHAR(16)"`
}

func (uc GroupsUsers) TableName() string {
	return "groups_users"
}
